package com.heeexy.example.controller;

import javax.servlet.http.HttpServletRequest;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;
import com.heeexy.example.service.EmpService;
import com.heeexy.example.util.CommonUtil;
@RestController
@RequestMapping("/emp")
public class EmpController {
	 @Autowired
	    private EmpService empService;
	    /**
	     * 查询文章列表
	     */
	  @RequiresPermissions("work:list")
	    @GetMapping("/list")
	    public JSONObject list(HttpServletRequest request) {
	       // return articleService.listArticle(CommonUtil.request2Json(request));
		  return empService.listEmp(CommonUtil.request2Json(request));
	    }

	    /**
	     * 查询薪水
	     */
	  @RequiresPermissions("work:listsal")
	    @GetMapping("/listsal")
	    public JSONObject listsal(HttpServletRequest request) {
	       // return articleService.listArticle(CommonUtil.request2Json(request));
	        return empService.listSal(CommonUtil.successJson());
	    }
	  /**
	     * 查询姓名
	     */
	  @RequiresPermissions("work:listname")
	    @GetMapping("/listname")
	    public JSONObject listEname(HttpServletRequest request) {
	       // return articleService.listArticle(CommonUtil.request2Json(request));
	        return empService.listEname(CommonUtil.request2Json(request));
	    }
	  /**
	     * 查询年龄
	     */
	  @RequiresPermissions("work:listage")
	    @GetMapping("/listage")
	    public JSONObject listEage(HttpServletRequest request) {
	       // return articleService.listArticle(CommonUtil.request2Json(request));
	        return empService.listEage(CommonUtil.request2Json(request));
	        
	    }
	  /**
	     * 新增员工
	     */
	 
	    @RequiresPermissions("work:add")
	    @PostMapping("/addEmp")
	    public JSONObject addEmp(@RequestBody JSONObject requestJson) {
//	        CommonUtil.hasAllRequired(requestJson, "content");
//	        return articleService.addArticle(requestJson);
	    	CommonUtil.hasAllRequired(requestJson, "ename,deptno,sal,edate,eage,eaddress");
	        return empService.addEmp(requestJson);
	    }
	    /**
	     * 修改商品
	     */
	    @RequiresPermissions("work:update")
	    @PostMapping("/updateEmp")
	    public JSONObject updateEmp(@RequestBody JSONObject requestJson) {
        CommonUtil.hasAllRequired(requestJson, "ename, deptno, sal,edate,eage,eaddress");
	    return empService.updateEmp(requestJson);

	    }
	    //删除商品
	    @RequiresPermissions("work:delete")
	    @PostMapping("/deleteEmp")
	    public  JSONObject deleteEmp(@RequestBody JSONObject requestJson){
	    	CommonUtil.hasAllRequired(requestJson, "ename");
	        return  empService.deleteEmp(requestJson);
	    }
}
